﻿using Loaf.Tools;
using Loaf.自定义控件.Controls;
using Prism.Mvvm;

namespace Loaf.Beans
{
    /// <summary>
    /// 上下文，存储程序的全部动态数据
    /// </summary>
    public class Context : BindableBase
    {
        /// <summary>
        /// 程序的属性
        /// </summary>
        public AppSetting AppSetting { get; set; }

        /// <summary>
        /// 书架的属性
        /// </summary>
        public BookSetting BookSetting { get; set; }

        /// <summary>
        /// 阅读器窗体
        /// </summary>
        public CustomWindow ReaderWindow { get; set; }

        /// <summary>
        /// 主窗体
        /// </summary>
        public CustomWindow MainWindow { get; set; }
    }

    public static class ContextExtension
    {
        /// <summary>
        /// 读取上下文
        /// </summary>
        /// <param name="context"></param>
        public static void ReadContext(this Context context)
        {
            context.AppSetting = JsonTool.ReadJson<AppSetting>("AppSetting");
            context.BookSetting = JsonTool.ReadJson<BookSetting>("BookSetting");
        }

        /// <summary>
        /// 写入上下文
        /// </summary>
        /// <param name="context"></param>
        public static void WriteContext(this Context context)
        {
            JsonTool.WriteJson(context.AppSetting, "AppSetting");
            JsonTool.WriteJson(context.BookSetting, "BookSetting");
        }

    }
}
